package _interview150;

import _object.TreeNode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 173. 二叉搜索树迭代器
 */
public class No173 {
    private final Queue<Integer> queue;

    public No173(TreeNode root) {
        queue = new LinkedList<>();
        dfs(root);
    }

    public int next() {
        return queue.poll();
    }

    public boolean hasNext() {
        return !queue.isEmpty();
    }

    private void dfs(TreeNode node) {
        if (node == null) return;
        dfs(node.left);
        queue.add(node.val);
        dfs(node.right);
    }
}
